// pages/article/readArticle.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let app=getApp();
    let that=this;
    //接收传送的数据
    const eventChannel= this.getOpenerEventChannel()
    eventChannel.on('acceptDataFromOpenerPage', function (data) {
      console.log('修改文章:',data.content)
      that.setData({
        themeName:getApp().globalData.presentTheme.deepColor.match(/wux-(\S*)/)[1],
        article:data.content
      })
    })
    const { windowHeight, platform } = wx.getSystemInfoSync()
    let editorHeight = windowHeight //占满屏幕
    this.setData({ editorHeight })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  onEditorReady() {
    const that = this
    let app=getApp()
    wx.createSelectorQuery().select('#editor').context(function (res) {
      that.editorCtx = res.context //必备初始化语句
      let article=that.data.article;
      if(article){
        var title=article.title;
        // that.editorCtx.insertText({html:`<h2>${title}</h2>`})
        that.editorCtx.setContents({
          // html:article.html,
          // text:article.text,
          delta:article.content,

          fail:res=>{
            console.log(res)
          }
        })
        that.setData({
          layoutPicture:article.layoutPicture,
          title:article.title,
          defaultValue1:article.title,
          subTitle:article.subTitle,
          defaultValue2:article.subTitle,
          image:article.image
        })
      }
    }).exec()
  },
  submitUpdate(){
    wx.showModal({
      showCancel:false,
      content:'该功能在测试中'
    })
  }
})